package cn.puge.insurance.ruler;

import cn.puge.insurance.c2s.C2sInsurance;
import cn.puge.insurance.mapper.domain.PugeInsurance;
import cn.puge.insurance.s2c.S2cInsurance;
import cn.puge.insurance.s2c.S2cInsuranceBanner;
import cn.puge.insurance.s2c.S2cInsuranceDeal;
import cn.puge.insurance.s2c.S2cInsurancePageInfo;
import cn.puge.insurance.service.IInsuranceSVC;
import cn.puge.insurance.utils.R;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: InsruanceRuler
 * @Description: 保险的Controller层
 * @Author: Gaoruiqi
 * @Date: 2025-11-11 21:36
 * @Version: 1.0
 **/

@RestController
@RequestMapping("/insurance")
public class InsuranceRuler {

    @Resource
    private IInsuranceSVC ipugeInsuranceSVC;

    /**
     * 获取保险轮播图
     *
     * @return
     */
    @PostMapping("/getInsuranceBannerList")
    public R getInsuranceBannerList() {
        try {
            List<S2cInsuranceBanner> s2CInsuranceBannerList = ipugeInsuranceSVC.getInsuranceBannerList();
            return R.ok().data("s2cInsuranceBannerList", s2CInsuranceBannerList);

        } catch (Exception e) {
            return R.error();

        } finally {
        }
    }

    /**
     * 获取保险详情
     *
     * @return
     */
    @PostMapping("/getInsuranceApplication")
    public R getInsuranceApplication(@RequestBody C2sInsurance c2sInsurance) {
        try {
            if (StringUtils.isEmpty(c2sInsurance.getInsuranceProductNum())) {
                return R.error().message("保险产品不存在！");
            }
            S2cInsurancePageInfo s2cInsurancePageInfo = ipugeInsuranceSVC.getInsuranceApplication(c2sInsurance.getInsuranceProductNum());
            return R.ok().data("s2cInsurancePageInfo", s2cInsurancePageInfo);
        } catch (Exception e) {
            return R.error();
        } finally {
        }
    }

    /**
     * 提交保单
     *
     * @return
     */
    @PostMapping("/publishInsuranceApplication")
    public R publishInsuranceApplication(@RequestBody C2sInsurance c2sInsurance) {
        try {
            PugeInsurance pugeInsurance = new PugeInsurance();
            BeanUtils.copyProperties(c2sInsurance, pugeInsurance);
            S2cInsuranceDeal s2cInsuranceDeal = ipugeInsuranceSVC.publishInsuranceApplication(pugeInsurance);
            return R.ok().data("s2cInsuranceDeal", s2cInsuranceDeal);
        } catch (Exception e) {
            return R.error();

        } finally {
        }
    }

}
